/*
 *  \file Utilities.h
 *  GRE
 *
 *  Created by Kutlak Roman on 05/03/2012.
 *  Copyright 2012 Kutlak Roman. All rights reserved.
 *
 */

#ifndef Utilities_h 
#define Utilities_h

#include <iostream>
#include <string>
#include <vector>
#include <exception>
#include <memory>


namespace std {
// missing from stl
template<typename T, typename ...Args>
std::unique_ptr<T> make_unique( Args&& ...args )
{
    return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
}
}

namespace kutlak {
namespace roman {
namespace gre {

#pragma mark -
#pragma mark string functions
    
    typedef std::vector<std::string> StringVector_t;
    
    //! Fast printing.
    inline void println(std::string const& msg)
    { std::cout << msg << '\n'; }
    
    //! \brief Split a string and return it as a vector of strings.
    StringVector_t 
    SplitString(std::string str, const std::string& delim = " ");

    //! \brief Remove any of the desired characters from the string
    std::string 
    RemoveChars(std::string str, const std::string& chars);

    /*! \brief Remove leading and trailing spaces
     *  \param singleSpaces if true all multiple white spaces within the string
     *  are replaced by a single space.
     */
    std::string
    Trim(std::string str, bool singleSpaces = true);
    
    
    /*! \brief Structure for handling deserialisation errors
     *  The member mData contains the data that have actually been read.
     */
    struct DeserialisationException : public std::runtime_error 
    {
        DeserialisationException(const std::string& exc,
                                 const std::string& read = "") : 
        std::runtime_error(exc), mData(read) {}
        
        DeserialisationException(std::string&& exc,
                                 std::string&& read) : 
        std::runtime_error(std::move(exc)), mData(std::move(read)) {}
        
        std::string data() const {
            return mData;
        }
        
    private:
        std::string mData;
    };
    
    
    struct RdfException : public std::runtime_error 
    {
        RdfException(const std::string& exc = "") : 
        std::runtime_error(exc) {}
    };
    
} // end namespace gre
}
}
#endif // Utilities_h
